from c06_tree.utils import TreeNode


def preorder(root):
    if not root: return
    print(root.val, end=" ")
    preorder(root.left)
    preorder(root.right)

def inorder(root):
    if not root: return
    inorder(root.left)
    print(root.val, end=" ")
    inorder(root.right)

def postorder(root):
    if not root: return
    postorder(root.left)
    postorder(root.right)
    print(root.val, end=" ")

root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root.left.right = TreeNode(5)
root.right.left = TreeNode(6)
root.right.right = TreeNode(7)
print("前序遍历:")
preorder(root)
print()
print("中序遍历:")
inorder(root)
print()
print("后序遍历:")
postorder(root)